<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="author" content="" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" />
<link href="../../css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="../../css/themes/mac_os_x.css" rel="stylesheet" type="text/css"/>
<link href="../../css/themes/alphacube.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../js/prototype.js"></script>
<script type="text/javascript" src="../../js/scriptaculous.js"></script>
<script type="text/javascript" src="../../js/page.js"></script>
<script type="text/javascript" src="../../js/window.js"></script>
<script type="text/javascript" src="../../js/window_effects.js"></script>
<script type="text/javascript">
var win;
var win2;
var messages = new Array('', 'Progetto inserito con successo', 'Progetto cancellato con successo', 'Progetto modificato con successo');
var index = 0;
function project(id){
    //var newwin = window.open_centered("dettaglio_progetto.php?id="+id, "doc", 650, 450, "");
    win = new Window({className: "mac_os_x", url: "dettaglio_progetto.php?id="+id,  width:530, height:450, zIndex: 100, top: 100, left: 100, resizable: true, title: "Dettaglio progetto", showEffect:Effect.Appear, hideEffect: Effect.Fade, draggable:true, wiredDrag: true});
	win.show(false);

	win2 = new Window({className: "mac_os_x", url: "elenco_docenti.php", top: 100, left: 700, width:650, height:500, zIndex: 100, resizable: true, title: "Elenco docenti", showEffect:Effect.Appear, hideEffect: Effect.Fade, draggable:true, wiredDrag: true});
}
</script>
</head>
<body <?php if(isset($_REQUEST['msg'])){ ?>onload="openInfoDialog(messages[<?php print $_REQUEST['msg'] ?>], 2)"<?php } ?>>
    <div id="header">
		<div class="wrap">
			<?php include "../header.php" ?>
		</div>
	</div>
	<div class="wrap">
	<div id="main" style="background-color: #FFFFFF; padding-bottom: 30px; width: 100%">
        <table class="admin_table">
            <tr class="admin_title_row">
                <td style="font-weight: bold" colspan="5" align="center">Elenco progetti: pagina <?php print $page ?> di <?php print $pagine ?></td>
            </tr>
            <tr>
                <td style="width: 30%" class="adm_titolo_elenco">Progetto</td>
                <td style="width: 40%" class="adm_titolo_elenco">Docenti</td>
                <td style="width: 10%" class="adm_titolo_elenco _center">Documenti</td>
                <td style="width: 10%" class="adm_titolo_elenco _center">AS</td>
                <td style="width: 10%" class="adm_titolo_elenco _center">Attivo</td>
            </tr>
            <tr class="admin_row">
                <td colspan="5"></td>
            </tr>
            <?php
            $x = 1;
            if($res_projects->num_rows > $limit)
                $max = $limit;
            else
                $max = $res_projects->num_rows;

            while($project = $res_projects->fetch_assoc()){
                if($x > $limit) break;
                $teachers = split("#", $project['referenti']);
                $teacs = join(", ", $teachers);
                $sel_teachers = "SELECT utenti.nome, utenti.cognome FROM utenti, docenti WHERE utenti.uid = docenti.id_docente AND id_docente IN ($teacs) ORDER BY cognome, nome";
                //print $sel_teachers;
                $res_teachers = $db->execute($sel_teachers);
                $teachers_string = array();
                while($ins = $res_teachers->fetch_assoc()){
                	array_push($teachers_string, $ins['cognome']." ".$ins['nome']);
                }
                $sel_docs = "SELECT COUNT(*) FROM documents WHERE progetto = ".$project['id_progetto'];
    			$count_docs = $db->executeCount($sel_docs);
            ?>
            <tr class="admin_row<?php if($x % 2) print(" odd") ?>">
                <td><a id="nome" href="#" onclick="project(<?php print $project['id_progetto'] ?>)"><?php print $project['nome'] ?></a></td>
                <td style="color: #003366"><?php print join(", ", $teachers_string) ?></td>
				<td style="color: #003366; text-align: right; padding-right: 15px"><?php print $count_docs ?></td>
                <td align="center" style="color: #003366"><?php print $project['anno'] ?></td>
                <td align="center" style="color: #003366"><?php if ($project['attivo'] == 1) print "SI"; else print "NO"; ?></td>
            </tr>
            <?php
                $x++;
            }
            include "../../shared/navigate.php";
            ?>
            <tr class="admin_row admin_menu">
                <td colspan="5">
                    <a href="#" onclick="project('0')" style="margin-right: 10px">Nuovo progetto</a>|
                    <a href="../index.php" style="margin-left: 10px">Torna al menu</a>
                </td>
            </tr>
            <tr class="admin_row">
                <td colspan="5"></td>
            </tr>
        </table>
        </div>
        <div id="footer">
			<p>Design: Luka Cvrk - <a href="http://www.solucija.com" title="Free Web Templates">Solucija</a></p>
		</div>
	</div>
</body>
</html>